package com.lry.basic.algorithm.niuke;

import java.util.*;

public class MergeTable {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        Map<Integer,Integer> map = new HashMap<>();

        while(n-->0){
            int key = scanner.nextInt();
            int value = scanner.nextInt();
            if(!map.containsKey(key)){
                map.put(key,value);
            }else {
                map.put(key,map.get(key)+value);
            }
        }
        Set<Integer> set =  map.keySet();
        Integer[] arr = set.toArray(new Integer[0]);
        Arrays.sort(arr);
        for(int key:arr){
            System.out.println(key+" "+map.get(key));
        }
    }
}
